'use strict';

angular.module('Help').controller('SocketController',
    ['$scope', '$resource', '$stateParams', 'BaseFunction', 'BaseSocket', '$location', 'Authentication',
    function($scope, $resource, $stateParams, BaseFunction, BaseSocket, $location, Authentication) {
    	$scope.message = '';
		$scope.messages = [];

		var socket = null;
		BaseSocket.connect(function(skt){
			socket = skt;
			socket.on('news', function(data) {
				$scope.messages.push(data.message);
				$scope.$digest();
			});

			socket.on('msg',function(data) {
				$scope.messages.push(data.message);
				$scope.$digest();
			});
		});
		

		$scope.btnSend = function(){
			socket.toAll('msg', {message:$scope.message});
			$scope.message = '';
		};

		$scope.btnOut = function(){
			socket.disconnect();
		};
    }
]);